package cn.nju.zyy.auction;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.Table;

@Entity
@Table(name = "ITEM")
@org.hibernate.annotations.BatchSize(size = 10)
@org.hibernate.annotations.DiscriminatorFormula("case when ITEM_IS_SPECIAL is not null then A else B end")
public class Item {

	private String name;
	private String description;
	private Set categories = new HashSet();

	public Item() {
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Set getCategories() {
		return Collections.unmodifiableSet(categories);
	}

	private void setCategories(Set categories) {
		this.categories = categories;
	}

	public void addCategory(Category category) {
		if (category == null)
			throw new IllegalArgumentException("Null category");
		category.getItems().add(this);
		categories.add(category);
	}
}
